<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>充值管理</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/form.css"/>
	
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script src="${pageContext.request.contextPath}/plugins/jQuery/easyui-lang-zh_CN.js"></script>
	
	<script src="${pageContext.request.contextPath}/admin/js/reg.js"></script>
	
	<script type="text/javascript">
		$(function(){
		     
		    $('#station').combobox({
				valueField:'station_id', //值字段
				textField:'station_name', //显示的字段
				url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1',
				onLoadSuccess : function(data) {
		            $('#station').combobox("setValue",-1);
	        	}
	        });
	        
	        $('#recharge_type').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"04","text":"转账"},
					{"value":"01","text":"现金"}
				],
				onLoadSuccess : function(data) {
		            $('#recharge_type').combobox("setValue","04");
	        	}
			});
			$('#recharge_type').combobox("setValue","04");
	        // url="${pageContext.request.contextPath}/dict/item/CHANGE_TYPE" data-options="valueField:'dict_code', textField:'dict_name',multiple:false,panelHeight:'auto'"
			
			loadTable();
			$('#dlg').dialog('close');
			
			//加载
            $('body').append('<div id="myWindow" class="easyui-dialog" closed="true"></div>'); 
            
            $('body').append('<div id="chargerd" class="easyui-dialog" closed="true"></div>'); 
            $('body').append('<div id="transrd" class="easyui-dialog" closed="true"></div>'); 
			
		});
		
		function loadTable(){
			$('#dg').datagrid({
				rownumbers:true,
				singleSelect:true,
				pagination:true,
				pageSize:20,
				pageList:[10,20,30,50,100],
		 		url:'${pageContext.request.contextPath }/admin/acct/custlist',
		 		queryParams:{
		 			 station:$('#station').combobox("getValue"),
		 			 custname:$('#custname').val(),
		 			 mobile:$('#mobile').val()
		 		},
	    		columns:[[
					{field:'cust_id',title:'编号',align:'center',width:80},
					{field:'cust_name',title:'客户姓名',align:'center',width:130},
					{field:'cust_sex',title:'性别',align:'center',width:40,formatter: function (value, row, index) {
						var res="";
						if(value==0){
							res="男";
						}else if(value==1){
							res= "女";
						}else{
							res="未知";
						}
						return res;
					}},
					{field:'cust_identity',title:'身份证号',align:'center',width:150},
					{field:'mobile',title:'联系电话',align:'center',width:100},
					{field:'station_name',title:'所属站点',align:'center',width:100},
					{field:'amountstr',title:'账户余额',width:130,align:'center',formatter: function (value, row, index) {
						return "￥"+value;
					}},
					{field:'pre_amount',title:'预充金额',width:130,align:'center',formatter: function (value, row, index) {
						return "￥"+value;
					}},
					{field:'operation',title:'操作选项',width:390,align:'left',formatter: function (value, row, index) {
						var str = '';
						str+=' <a href="javascript:pre_pay(\''+row.cust_id+'\',\''+row.station_id+'\',\''+row.amountstr+'\',\''+row.cust_name+'\')" name="pre_pay"  class="easyui-linkbutton" ></a>';
						if(row.pre_amount!=0){
							str+=' <a href="javascript:pay(\''+row.acct_id+'\')" name="pay"  class="easyui-linkbutton" ></a>';
						}					
						str+=' <a href="javascript:chargerd(\''+row.acct_id+'\')" name="charge_record"  class="easyui-linkbutton" ></a>';
						str+=' <a href="javascript:transrd(\''+row.acct_id+'\')" name="trans_record"  class="easyui-linkbutton" ></a>';
						str+=' <a href="javascript:returnbill(\''+row.cust_id+'\')" name="returnbill"  class="easyui-linkbutton" ></a>';
						return str;
					}}
	 			]],
				onLoadSuccess:function(data){  
			        $("a[name='pre_pay']").linkbutton({text:'预充值',plain:true,iconCls:'icon-my-add'});
			        $("a[name='pay']").linkbutton({text:'<span style="color:red;">确认充值</span>',plain:true,iconCls:'icon-ok'});
			        $("a[name='charge_record']").linkbutton({text:'充值记录',plain:true,iconCls:'icon-search'});
			        $("a[name='trans_record']").linkbutton({text:'交易记录',plain:true,iconCls:'icon-edit'});
			        $("a[name='returnbill']").linkbutton({text:'退赔',plain:true,iconCls:'icon-my-add'});
				}
			});
		}
		
		function returnbill(custid){
			location.href="${pageContext.request.contextPath }/admin/return/addreturnbillbefore/"+custid
		}
		
		//预充值
		function pre_pay(cust_id,station_id,amount,cust_name){
		    
		    $('#dlg').dialog('open').dialog('setTitle','预充值');
	        //$('#fm').form('clear');
	        
            $('#bank_type').combobox("setValue",'-1');
  //        $('#recharge_type').combobox("setValue",'-1');
            $("#t_amount").textbox('setValue',amount);
            $("#cust_id").val(cust_id);
            $("#station_id").val(station_id);
            $("#cust_name").val(cust_name);
            $('#station_name').combobox({
				valueField:'station_id', //值字段
				textField:'station_name', //显示的字段
				url:'${pageContext.request.contextPath }/admin/station/findStationByKind/1',
				onLoadSuccess : function(data) {
		            $('#station_name').combobox("setValue",station_id);
	        	}
	        });
	     
	        
		}
		
		function pay(acct_id){
		   var obj= $('#myWindow');
	//	   showMyWindow("确认充值",'${pageContext.request.contextPath }/admin/acct/reindex/'+acct_id, 1000, 500,true,false,false,obj);
			location.href="${pageContext.request.contextPath }/admin/acct/reindex/"+acct_id, 1000, 500,true,false,false,obj;
		}
		
		function chargerd(acct_id){
		    var obj= $('#chargerd');
		//   showMyWindow("充值记录",'${pageContext.request.contextPath }/admin/acct/rechargeindex/'+acct_id, 1000, 500,true,false,false,obj);
		   location.href="${pageContext.request.contextPath }/admin/acct/rechargeindex/"+acct_id, 1000, 500,true,false,false,obj;
		}
		
		function transrd(acct_id){
		   var obj= $('#transrd');
		//   showMyWindow("交易记录",'${pageContext.request.contextPath }/admin/acct/transrdindex/'+acct_id, 1000, 500,true,false,false,obj);
		   location.href="${pageContext.request.contextPath }/admin/acct/transrdindex/"+acct_id, 1000, 500,true,false,false,obj;
		}
		
	   function saverecharge(){
	   		var amount=$('#amount').val();
	   		if($.trim(amount)==''){
				$.messager.alert('系统消息','充值金额必须输入！');
				$('#amount').focus(); 
	    		return;
			}else{
			   if(!isSignInteger(amount))
			   {
			       $.messager.alert('系统消息','充值金额必须正整数！');
				   $("#amount").val('');
	    		   return;
			   }
			}
	   		var rechargemsg="请确认对客户"+$("#cust_name").val()+"充值<span style='color:red'>￥"+amount+"</span>元？";
	   		$.messager.confirm('系统消息',rechargemsg, function(r){
	   			if(r){	
					
			        var url = "${pageContext.request.contextPath }/admin/acct/rechargeBill";
					var formdata = $('#fm').serialize();
					$.ajax({
					type: "POST",
					url: url,
					data:formdata,// 要提交表单的ID
					success: function(result){
							if(result=='0'){
								$.messager.alert('系统消息','充值成功');
								$('#dlg').dialog('close');		// close the dialog
					//			$.messager.show({title:'预充值',msg:'保存成功！',timeout:6,showType:'slide'});
								$('#dg').datagrid('reload');	// reload the user data
							}else{
							  $.messager.alert('系统消息','<span style=\"color:red;\">提交表单失败，请稍后再试！</span>');
							}
					},
					error : function(msg) {
						console.info(msg);
					}
				   });
	   			}else{
	   				$.messager.alert('系统消息','<span style=\"color:green;\">预充值操作取消！</span>');
	   			}
	   		});
	        
	    }
		
		function showImg(imgUrl){
			$('#dlg').dialog('open');
			var image=document.getElementById("stationImg");
			var src="${pageContext.request.contextPath }"+imgUrl;
			image.setAttribute("src",src );
		}

		// 打开一个新的选项卡，并制定选项卡的名称
		function show(url,name){
			parent.window.addTab(name,url);
		}
		
		function findData(){
			loadTable();
		}
		
		function showMyWindow(title, href, width, height,modal,minimizable,maximizable,obj) {  
          obj.window(  
                        {  
                            title : title,  
                            width : width === undefined ? 600 : width,  
                            height : height === undefined ? 400 : height,  
                            content : '<iframe scrolling="yes" frameborder="0"  src="'  
                                    + href  
                                    + '" style="width:100%;height:98%;"></iframe>',  
                            modal : modal === undefined ? true : modal,  
                            minimizable : minimizable === undefined ? false  
                                    : minimizable,  
                            maximizable : maximizable === undefined ? false  
                                    : maximizable,  
                            shadow : false,  
                            cache : false,  
                            closed : false,  
                            collapsible : false,  
                            resizable : false,
                            top:($(window).height() - height)/2,   
                            left:($(window).width() - width)/2,
                            loadingMessage : '正在加载数据，请稍等片刻......'  
                        });  
       }
       
       // 清除已经上传的图片，重新上传
       	function clearImgs(){
			$("#show").html("");
			$("#pictureSrc").val("");
		}
		
		function findActivityAmount(value){
			var sid=$("#station_id").val();
			$.post("${pageContext.request.contextPath}/admin/acct/findActivityAmount",{stationid:sid,amount:value},
				function(data){
					if(data=="0"){
						$("#actMsg").html("没有任何活动");
					}else{
						var msg="（该客户参加了充"+value+"送"+data+"元的活动）";
						$("#actMsg").html(msg);
					}
					$("#activity_amount").val(data);
					
					var totalAmount=parseInt(value)+parseInt(data);
					$("#totalAmount").html("￥"+totalAmount+"元");	
				},"text");
		}

	</script>
	<style type="text/css">
		body{
		font-family:'微软雅黑';}
	</style>
  </head>
  
  <body>
	<table id="dg" title="充值管理" toolbar="#searchtool" loadMsg="正在查询..." style="width:90%;height:auto;"></table>
	
    <div id="searchtool" style="padding:5px; height:auto;">  
       <span style="margin:0px 12px;">站点:</span><input id="station" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">姓名:</span><input id="custname" class="easyui-textbox" style="width:180px;height:26px"/> 
       <span style="margin:0px 12px;">手机号码:</span><input id="mobile" class="easyui-textbox" style="width:180px;height:26px"/> 
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" style="width:100px;margin:0px 3px;">查询</a>
       <a href="javascript:findData()" class="easyui-linkbutton" data-options="iconCls:'icon-reload'" style="width:100px;margin:0px 3px;">刷新</a>
    </div>
    
   <div id="dlg" class="easyui-dialog" style="width:750px;height:500px;padding:10px 20px" closed="true" buttons="#dlg-buttons">
	 <div class="ftitle">预充值</div>
	  <form id="fm" method="post" enctype="multipart/form-data">
	
			<div class="fitem">
				<label>账户余额:</label>
				<input id="t_amount" name="t_amount" readonly class="easyui-textbox" style="width:210px;height:26px"/>
				
				<input id="cust_id" name="cust_id" type="hidden" />
				<input id="station_id" name="station_id" type="hidden" />&nbsp;&nbsp;&nbsp;
				<input id="cust_name" name="cust_name" type="hidden" />
				<label>所属服务站:</label>
				<input id="station_name" class="easyui-textbox" readonly style="width:210px;height:26px"/>
			</div>
			
			<div class="fitem">
				<label>付款方式:</label>
				<input id="recharge_type" name="recharge_type"  class="easyui-combobox" style="width:210px;height:26px"/><span style="color:red;">*</span>&nbsp;&nbsp;&nbsp;
				
				<label>转账银行:</label>
				<input id="bank_type" name="bank_type" url="${pageContext.request.contextPath}/dict/item/BANK_TYPE" data-options="valueField:'dict_code', textField:'dict_name',multiple:false,panelHeight:'auto'" class="easyui-combobox" style="width:210px;height:26px"/>
			</div>
			
			<div class="fitem">
				<label>开户行:</label>
				<input id="bank_name" name="bank_name" class="easyui-textbox" style="width:210px;height:26px"/>&nbsp;&nbsp;&nbsp;&nbsp;
				
				<label>转账者姓名:</label>
				<input id="buyer_login_id" name="buyer_login_id" class="easyui-textbox" style="width:210px;height:26px"/>
			</div>
			
			<div class="fitem">
				<label>充值金额:</label>
				<input id="amount" name="amount"  style="width:210px;height:26px" onchange="findActivityAmount(this.value)"/><span style="color:red;">*</span>&nbsp;&nbsp;&nbsp;
				
				<label>活动金额:</label> 
 				<input id="activity_amount" name="activity_amount" readonly="readonly"  style="width:210px;height:26px;color:red;" value="0"/> 
			</div>

           <div class="fitem">
				<label>转账流水号:</label>
				<input id="trade_no" name="trade_no" class="easyui-textbox" style="width:210px;height:26px"/>&nbsp;&nbsp;&nbsp;
				<span style="color:red;" id="actMsg">&nbsp;</span>
			</div>
			
			<div class="fitem">
				<label>凭证上传:</label>
		<!-- 		<input class="easyui-filebox" name="image" id="imageFile" data-options="prompt:'请选择凭证图片...'" style="width:210px" accept="image/gif,image/jpeg,image/png"/>&nbsp;&nbsp;&nbsp;
		 	-->	<input type="file" name="image" id="imageFile">
				<button id="upload" onclick="return false;">上传凭证</button>
				<a href="javascript:clearImgs()" class="easyui-linkbutton" data-options="iconCls:'icon-my-clear'" style="width:100px;margin:0px 3px;">清空凭证</a> 
				
				<!-- 存储图片地址，并显示图片 -->
				<input type="hidden" name="rootPath" id="rootPath" value="${pageContext.request.contextPath }">
				<input type="hidden" name="pictureSrc" id="pictureSrc">
			</div>
			<div class="fitem" id="show"></div>
			<div class="fitem">
				<label>合计充值金额:</label>
				<span id="totalAmount" style="color:red;">￥0.00元</span>
			</div>
		</form>
		
  </div>
  <div id="dlg-buttons">
	<a href="#" class="easyui-linkbutton" id="add" iconCls="icon-add" onclick="saverecharge()">充值</a>
	<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">关闭</a>
  </div>
  	<script type="text/javascript" src="${pageContext.request.contextPath }/plugins/upload/ajaxfileupload.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/plugins/upload/upload.js"></script>  
  </body>
</html>
